package com.baigt.jvm.thread;

/**
 * 类功能描述:
 *
 * @author baigt
 * @version V1.0
 * @since 2019-07-14 15:04
 */
public class _003SaleTrainTicket {
    public static void main(String[] args) {
            TicketSaleWindow thread1=new TicketSaleWindow("柜台1");
            TicketSaleWindow thread2=new TicketSaleWindow("柜台2");
            TicketSaleWindow thread3=new TicketSaleWindow("柜台3");
            thread1.start();
            thread2.start();
            thread3.start();
    }
}

/**
 * 下边的线程有什么问题？可以保证执行结果的正确性吗？
 */
class TicketSaleWindow extends Thread {
    private static final int ticketNum=50;
    private static int  index=1;

    public TicketSaleWindow(String name) {
        super(name);
    }

    @Override
    public void run() {
        while (index<=ticketNum) {
            System.out.println(""+Thread.currentThread().getName()+"sale:"+index++);
        }
    }
}




